/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manejadores;

import beans2.Recurso;
import java.sql.*;
import java.util.ArrayList;

/**
 *
 * @author Jose Dario Gimenez
 */
public class ManejadorRecurso {

    private Recurso recurso;
    private ResultSet resultSet;
    private ArrayList list;
    private Connection connection;

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public void setCondition(String condition) throws SQLException {
        if (!condition.equalsIgnoreCase("")) {
            condition = " where " + condition;
        }
        list = new ArrayList();
        PreparedStatement statement = connection.prepareStatement("select idrecurso, estado, idtiporecurso from recurso" + condition + " order by idtiporecurso, idrecurso");
        resultSet = statement.executeQuery();
        while (resultSet.next()) {
            recurso = new Recurso();
            recurso.setId(resultSet.getInt(1));
            recurso.setEstado(resultSet.getString(2));
            int idTipoRecurso = resultSet.getInt(3);
            ManejadorTipoRecurso manejadorTipoRecurso = new ManejadorTipoRecurso();
            manejadorTipoRecurso.setConnection(connection);
            manejadorTipoRecurso.setConditionRecurso("idtiporecurso=" + idTipoRecurso, recurso.getId());
            recurso.setTipoRecurso(manejadorTipoRecurso.getTipoRecurso());
            list.add(recurso);
        }
    }

    public ArrayList getList() {
        return list;
    }

    public Recurso getRecurso() {
        return recurso;
    }

}
